fix(godot-cpp): force-include <cstdlib>, broken on libc++ 22 - #146
Merged
Conversation
src/godot.cpp calls realloc() and free() while including neither <cstdlib> nor <stdlib.h> -- it has been riding on a transitive include all along. libstdc++ and libc++ up to 20 still provide one; libc++ 22 does not: src/godot.cpp:252: error: use of undeclared identifier 'realloc' src/godot.cpp:270: error: use of undeclared identifier 'free' Both 4.5.0 and 10.0.0-rc1 carry it, so the fix is not version-gated. CI missed it because the only LLVM legs are macOS and Windows and both pin llvm@20.1.7, while the linux leg is gcc -- linux-with-a-newer-libc++ is a combination the matrix never builds. It surfaced in a real GDExtension project pinned to llvm@22.1.8, which had to pin gcc@16 to work around it. A force-include rather than a generated shim header: the translation unit at fault is the PACKAGE's own, and a dependency compiles with its own include path, so nothing a consumer ships -- including the header-shadow mechanism godot-cpp-m uses for its module unit -- can reach it. cxxflags rather than cflags: this package has no C sources and cflags never reaches a .cpp. Verified with mcpp 2026.8.3.3 + llvm@22.1.8 on linux: compat.godot-cpp 4.5.0 and 10.0.0-rc1 both build and run; `import godot_cpp;` through godotengine.godot-cpp-m 10.0.0-rc1 builds and runs; and the reporting project builds its player GDExtension (libplayer.so) with its gcc pin lifted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
compat.godot-cpp'ssrc/godot.cppcallsrealloc()andfree()while including neither<cstdlib>nor<stdlib.h>— it has been riding on a transitive include all along. libstdc++ and libc++ up to 20 still provide one; libc++ 22 does not:Both 4.5.0 and 10.0.0-rc1 carry it, so the fix is not version-gated.
Why CI is green today
The only LLVM legs are
workspace (macos)andworkspace (windows), and both pin llvm@20.1.7; the linux leg is gcc. Linux-with-a-newer-libc++ is a combination the matrix never builds, so nothing here ever compiled these sources against a libc++ that had dropped the transitive include.It surfaced in a real GDExtension project pinned to
llvm@22.1.8, which had to work around it with agcc@16.1.0pin.Why a force-include and not a shim header
The translation unit at fault is the package's own. A dependency compiles with its own include path, so nothing a consumer ships can reach it — including the header-shadow mechanism
godot-cpp-muses for its module unit, which only ever applies to that package's TUs. Patching the mirror archive was the other option and was rejected:tools/godot-cpp/repack.shexists to guarantee the archive is upstream byte-for-byte, and it refuses to publish otherwise.cxxflagsrather thancflags: this package has no C sources, andcflagsnever reaches a.cpp.Upstream should of course just add the include; this is the index-side unblock in the meantime.
Verification
mcpp 2026.8.3.3 +
llvm@22.1.8on linux, all previously failing:And the reporting project, with its
gcc@16.1.0pin lifted:gcc 16 is unaffected (the flag is a no-op there —
<cstdlib>was already coming in).Follow-up worth considering
Nothing in CI would catch a regression, because no leg builds these packages against libc++ ≥ 22. A dedicated member pinned to
llvm@22.1.8would close that, at the cost of another full godot-cpp build per platform — worth deciding separately rather than folding in here.Design notes:
.agents/docs/2026-08-04-add-godot-cpp-10.0.0-rc1.md§8.